<%--
*
* 作者： Sky
*
* 描述： 流程导航
*
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:directive.page import="java.util.List"/>
<jsp:directive.page import="com.sky.common.string.StringUtils"/>
<jsp:directive.page import="java.util.ArrayList"/>
<jsp:directive.page import="java.util.Map"/>
<jsp:directive.page import="com.sky.common.json.JSONUtils"/>
<jsp:directive.page import="java.net.URLDecoder"/>
<jsp:directive.page import="com.toncen.samepms.system.dao.CodeDao"/>
<jsp:directive.page import="com.toncen.samepms.system.domain.Code"/>
<jsp:directive.page import="com.toncen.samepms.system.domain.CodeItem"/>
<jsp:directive.page import="com.sky.common.sql.JavaSQLUtils"/>
<head>
	<title>流程导航</title>
	<%@include file="/share/header.jsp"%>
<style type="text/css">
<!--
.flow03 {
	font-size: 12px;
	color: #000000;
	background-image: url(../image/flowbg03.jpg);
	border: 1px solid #A7A7A7;
	vertical-align: middle;
	margin-right: 5px;
	margin-left: 5px;
	padding-right: 5px;
	padding-left: 5px;
}
.flow02 {
	font-size: 12px;
	color: #000000;
	background-image: url(../image/flowbg02.jpg);
	border: 1px solid #E59915;
	vertical-align: middle;
	margin-right: 5px;
	margin-left: 5px;
	padding-right: 5px;
	padding-left: 5px;
}
.flow01 {
	font-size: 12px;
	color: #000000;
	background-image: url(../image/flowbg01.jpg);
	border: 1px solid #7DAECC;
	vertical-align: middle;
	margin-right: 5px;
	margin-left: 5px;
	padding-right: 5px;
	padding-left: 5px;
}
-->
</style>	
</head>
<%
    String strCode=request.getParameter("code");//流程编码
    String process=request.getParameter("process");//流程json字符串
    if(!StringUtils.isEmpty(process)){
    	//System.out.println(process);
    	process=URLDecoder.decode(process,"UTF-8");
    	//System.out.println(process);
    }    
    String exclude=request.getParameter("exclude");//排除流程节点
    String value=request.getParameter("value");//当前流程节点
    //out.println("code=["+strCode+"]\texclude=["+exclude+"]\tvalue=["+value+"]\tprocess=["+process+"]");
    List<CodeItem> codeItemList=new ArrayList<CodeItem>(5);
    if(!StringUtils.isEmpty(process)){//有设置流程json字符串
    	List<Map<String,Object>> resultList=(List<Map<String,Object>>)JSONUtils.JSON2object(process.replaceAll("'","\""));
		for(Map<String,Object> result:resultList){
			if(result.get("sequence")==null){
				result.put("sequence",codeItemList.size()+resultList.indexOf(result)+1);
			}
			result.put("class", CodeItem.class.getName());
		}
		codeItemList.addAll((List<CodeItem>)JSONUtils.JSON2object(JSONUtils.object2JSON(resultList))); 
    }
    if(!StringUtils.isEmpty(strCode)){//有设置流程编码
	    CodeDao codeDao=new CodeDao();
	    Code code=codeDao.getByCode(strCode);
	    codeItemList.addAll(code.getCodeItemList());
	}  
    StringBuffer strSQL = new StringBuffer();
    strSQL.append(" select * from ");
    strSQL.append(CodeItem.class.getName());
    strSQL.append(" order by sequence asc,value asc ");	
    codeItemList=(List)JavaSQLUtils.execute(codeItemList,strSQL.toString());   
%>
<%!
	boolean isExclude(String value,String exclude){
		boolean result=false;
	    if(!StringUtils.isEmpty(exclude)){
	    	String[] excludes=exclude.split(",");//按照英文逗号拆分排除结点
			for(String e:excludes){
				if(value.equals(e)){//排除的
					result=true;
					break;
				}
			}	    	
	    }	
	    return result;
	}
 %>
<body>
 <fieldset style="margin:0 8px 0 8px;">
	<legend>业务办理导航：</legend>
	<table border="0">
	  <tr>
<% 
	int index=0;//结点位置
	CodeItem codeItem;
	String styleColor="";
	String styleClass="";
	String name;
	String discription;
	int sequence=Integer.MAX_VALUE;//当前活动顺序
	for(int i=0;i<codeItemList.size();i++){
		codeItem=codeItemList.get(i);
		if(isExclude(codeItem.getValue(),exclude)){
			//out.println("排除：["+codeItem.getValue()+"]");
			continue;
		}
		index++;
		name=index+".【"+codeItem.getName()+(ComitConstant.isDeveloperMode()?"("+codeItem.getValue()+")":"")+"】";
		discription=name+"：\n"+(StringUtils.isEmpty(codeItem.getRemark())?"暂无说明":codeItem.getRemark());
		if(codeItem.getValue().equals(value)){//当前活动
			styleClass="flow02";
			styleColor="#000099";
			sequence=codeItem.getSequence();
		//} else if(index==1){//起始活动
		//	styleClass="#00FF00";
		//	styleColor="#00FF00";
		//} else if(i==codeItemList.size()-1){//结束活动
		//	styleClass="flow01";
		//	styleColor="flow01";
		} else if(codeItem.getSequence()<sequence){//已经完成活动
			styleClass="flow03";
			styleColor="#A7A7A7";
		} else {//未完成活动
			styleClass="flow01";
			styleColor="#006600";
		}
%>	  
<%
		if(index!=1){//起始活动
%>		
	    <td>>></td>
<%
		}
%>		    
	    <td class="<%=styleClass%>" title="<%=discription%>"><span style="color:<%=styleColor%>;font-weight: bold;font-size: 12px;"><%=name%></span></td>   
<% 
	}
%>	 	             
	  </tr>
	</table>
 </fieldset>	
</body>
</html>
